package be.bejug.scrumadmin.components;

import be.bejug.scrumadmin.domain.Task;
import be.bejug.scrumadmin.spring.ApplicationHolder;

import com.vaadin.terminal.ThemeResource;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.VerticalLayout;

/**
 * Task card panel.
 * 
 * @author GDAFJ73
 * 
 */
public class TaskCard extends Panel {

	/**
	 * Serial Version UID.
	 */
	private static final long serialVersionUID = -356811082051553484L;

	/**
	 * The task.
	 */
	private final Task task;

	/**
	 * Constructor.
	 * 
	 * @param task
	 *            the task
	 */
	public TaskCard(final Task task) {
		super(task.getName() + " - (" + task.getWorkLeft().toString() + " / "
				+ task.getEstimation().toString() + ")");

		this.task = task;

		setIcon(new ThemeResource("images/"
				+ task.getPriority().getIconFileName()));

		addComponents();
	}

	/**
	 * Adds components to the task card.
	 */
	private void addComponents() {
		VerticalLayout verticalLayout = new VerticalLayout();

		Label description = new Label(
				ApplicationHolder.getMessage("task.description.label") + ": "
						+ getTask().getDescription());

		Button detailButton = new Button(
				ApplicationHolder.getMessage(("task.details.label")));

		verticalLayout.addComponent(description);
		verticalLayout.addComponent(detailButton);

		addComponent(verticalLayout);

	}

	/**
	 * Gets the task.
	 * 
	 * @return the task
	 */
	public Task getTask() {
		return task;
	}

}
